package com.liangzhong.model.rankinglist
{
	import com.liangzhong.constants.ClubConst;
	import com.liangzhong.model.AppData;
	
	import flash.utils.Dictionary;

	/**
	 *排行榜 
	 * @author Administrator
	 * 
	 */	
	public class RankinglistDataManager
	{
		/**
		 * 
		 */
		public var _dic:Dictionary = new Dictionary();
		
		/**
		 *国家排行 
		 */
		public var nationDic:Dictionary = new Dictionary();
		public function RankinglistDataManager()
		{
		}
		
		/**
		 *获得排行榜信息 
		 * 
		 */
		public function analysisRankingInfo($obj:Object):void
		{
			
			if($obj.type == 7)
			{
				if($obj.ranklist == null)return;
				var obj:Object = $obj.ranklist;
				analysisNationRanking(ClubConst.COUNTRY_ENGLAND,obj.england,$obj.selfrank);
				analysisNationRanking(ClubConst.COUNTRY_SPAIN,obj.spain,$obj.selfrank);
				analysisNationRanking(ClubConst.COUNTRY_FRANCE,obj.french,$obj.selfrank);
				analysisNationRanking(ClubConst.COUNTRY_GERMANY,obj.germary,$obj.selfrank);
				analysisNationRanking(ClubConst.COUNTRY_ITALY,obj.italy,$obj.selfrank);
				analysisNationRanking(ClubConst.COUNTRY_CHAIN,obj.china,$obj.selfrank);
				
				_dic[$obj.type] = {selfrank:$obj.selfrank,time:AppData.getInstance().time};
			}else
			{
				var arr:Array = $obj.ranklist;
				var vo:RankingListVo;
				var len:int = arr.length;
				var list:Array = [];
				var i:int ;
				var selfSort:int = 0;//自己的排名
				var clubId:int = AppData.getInstance().clubDatamanager.clubInfo.clubid;
				for(i = 0;i < len;i++)
				{
					vo = new RankingListVo();
					vo.analysis(arr[i]);
					vo.rankingType($obj.type);
					
					list.push(vo);
				}
				list.sort(sortRank);
				for(i = 0;i < len;i++)
				{
					vo = list[i];
					vo.sort = i + 1;
					if(vo.clubid == clubId)
					{
						selfSort = vo.sort;
					}
				}
				_dic[$obj.type] = {selfrank:selfSort,list:list,time:AppData.getInstance().time};
			}
			
		}
		private function sortRank(a:RankingListVo,b:RankingListVo):Number
		{
			if(a.value > b.value )return -1;
			if(a.value < b.value)return 1;
			return 0;
		}
		
		private function analysisNationRanking($type:int,$arr:Array,selfrank:int):void
		{
			if($arr == null)
			{
				nationDic[$type] = {selfrank:selfrank,list:[]};
				return;
			}
			var vo:RankingListVo;
			var len:int = $arr.length;
			var list:Array = [];
			var i:int = 0;
			for(i = 0;i < len;i++)
			{
				vo = new RankingListVo();
				vo.analysis($arr[i]);
				list.push(vo);
			}
			list.sort(sortRank);
			var selfSort:int = 0;//自己的排名
			var clubId:int = AppData.getInstance().clubDatamanager.clubInfo.clubid;
			for(i = 0;i < len;i++)
			{
				vo = list[i];
				vo.sort = i + 1;
				if(vo.clubid == clubId)
				{
					selfSort = vo.sort;
				}
			}
			
			
			
			nationDic[$type] = {selfrank:selfSort,list:list};
		}
	}
}